package cn.qy.java.base.ch21;

/**
 * dead lock 案例
 *
 * @author acc8226
 */
public class Ch21_01_DeadLockDemo {
	
	static class ThreadA extends Thread {
		@Override
		public void run() {
			synchronized (ThreadA.class) {
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				synchronized (ThreadB.class) {
				}
			}
			
		}
	}
	
	static class ThreadB extends Thread {
		@Override
		public void run() {
			synchronized (ThreadB.class) {
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				synchronized (ThreadA.class) {
				}
			}
			
		}
	}

	public static void main(String[] args) throws InterruptedException {
		new ThreadA().start();
		new ThreadB().start();
	}

}
